﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wallpaper.Models.Entities;

namespace Wallpaper.Data.Configurations
{
    public class CarouselConfiguration : IEntityTypeConfiguration<Carousel>
    {
            public void Configure(EntityTypeBuilder<Carousel> builder)
            {
                // 设置表名
                builder.ToTable("carousels");  

                // 配置主键
                builder.HasKey(c => c.Id);

                builder.Property(c => c.Id)
                       .IsRequired()
                       .HasMaxLength(36);

                // 配置 Title
                builder.Property(c => c.Title)
                       .IsRequired()
                       .HasMaxLength(100)
                       .HasComment("轮播图标题");

                // 配置 CarouselUrl - 删除列名配置
                builder.Property(c => c.CarouselUrl)
                       .IsRequired()
                       .HasMaxLength(500)
                       .HasComment("轮播图URL");

                // 配置 SortOrder - 删除列名配置
                builder.Property(c => c.SortOrder)
                       .IsRequired()
                       .HasDefaultValue(0)
                       .HasComment("排序序号");

                // 配置 IsActive - 删除列名配置
                builder.Property(c => c.IsEnabled)
                       .IsRequired()
                       .HasDefaultValue(true)
                       .HasComment("是否启用");

                // 配置 CreatedAt
                builder.Property(c => c.CreatedAt)
                       .IsRequired()
                       .HasDefaultValueSql("GETDATE()")  // SQL Server 使用 GETDATE()
                       .HasComment("创建时间");

                // 配置 UpdatedAt
                builder.Property(c => c.UpdatedAt)
                       .HasComment("更新时间");

                // 添加索引
                builder.HasIndex(c => new { c.IsEnabled, c.SortOrder })
                       .HasDatabaseName("IX_Carousels_Active_Sort");

                builder.HasIndex(c => c.CreatedAt)
                       .HasDatabaseName("IX_Carousels_CreateAt");
            }
        }
}
